import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页管理', icon: 'dashboard' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

// export const asyncRoutes = [houserManage, permission, categories]
import categories from './modules/categories'
import houserManage from './modules/houserManage'
import permission from './modules/permissions'
import rolesRouter from './modules/roles'
import business from './modules/business'
// import clientRouter from './modules/client'
import pagesRouter from './modules/pages'

// 引入多个模块的规则

export const asyncRoutes = [houserManage, permission, business, categories, rolesRouter, pagesRouter]

// 引入多个模块的规则
// import clientRouter from './modules/client'

// 动态路由

// export const asyncRoutes = [houserManage, permission, categories]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes, ...asyncRoutes]
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
